package com.leenmvc.core.base;

import com.leenmvc.core.dao.communal.Dialect;
import com.leenmvc.core.enums.EntityInfoEnum;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class EntityInfo {

    /**
     * 表注解
     */
    private String tableComment;

    /**
     * 使用什么方言
     */
    private Dialect dialect;

    /**
     * 实体对应的数据表名
     */
    private String tableName;

    /**
     * 主键字段名称
     */
    private String primaryFieldName;

    /**
     * 主键数据表字段名称
     */
    private String primaryColumnName;

    /**
     * 实体
     */
    private Class entity;

    /**
     * Excel表格导出模板类
     */
    private Class excelEntity;

    private String schema;

    private String sourceGroup;

    /**
     * 对应于实体类的Dao, Service, Controller
     */
    private Class[] correspondingClss;
    /**
     * 根据不同的条件组成不同的字段数组
     * 因为主要是做迭代，所以采用数组
     */
    private Map<EntityInfoEnum, Field[]> fieldMap;
    /**
     * 根据不同的条件组成不同的字段字符串表示数组
     * 因为主要是做迭代，所以采用数组
     */
    private Map<EntityInfoEnum, String[]> fieldStrMap;

    public EntityInfo(Class<?> entity) {
        this.entity = entity;
        this.fieldMap = new HashMap<>();
        this.fieldStrMap = new HashMap<>();
        this.correspondingClss = new Class[4];
    }

    public String getPrimaryColumnName() {
        return primaryColumnName;
    }

    public void setPrimaryColumnName(String primaryColumnName) {
        this.primaryColumnName = primaryColumnName;
    }

    public String getTableName() {
        return tableName;
    }

    public String getPrimaryFieldName() {
        return primaryFieldName;
    }

    public void setPrimaryFieldName(String primaryFieldName) {
        this.primaryFieldName = primaryFieldName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public Dialect getDialect() {
        return dialect;
    }

    public void setDialect(Dialect dialect) {
        this.dialect = dialect;
    }

    public String getTableComment() {
        return tableComment;
    }

    public void setTableComment(String tableComment) {
        this.tableComment = tableComment;
    }

    public Class getEntity() {
        return entity;
    }

    public void setEntity(Class entity) {
        this.entity = entity;
    }

    public Class[] getCorrespondingClss() {
        return correspondingClss;
    }

    public Class<?> getDaoClass() {
        return this.correspondingClss[0];
    }

    public Class<?> getServiceClass() {
        return this.correspondingClss[1];
    }

    public Class<?> getControllerClass() {
        return this.correspondingClss[1];
    }

    public void setCorrespondingClss(Class[] correspondingClss) {
        this.correspondingClss = correspondingClss;
    }

    public void setDaoClass(Class<?> cls) {
        this.correspondingClss[3] = cls;
    }

    public void setEntityClass(Class<?> cls) {
        this.correspondingClss[0] = cls;
    }

    public void setServiceClass(Class<?> cls) {
        this.correspondingClss[1] = cls;
    }

    public void setControllerClass(Class<?> cls) {
        this.correspondingClss[2] = cls;
    }

    public Map<EntityInfoEnum, Field[]> getFieldMap() {
        return fieldMap;
    }

    public Field[] getFieldArray(EntityInfoEnum entityInfoEnum) {
        return this.fieldMap.get(entityInfoEnum);
    }

    public void putFieldArray(EntityInfoEnum entityInfoEnum, Field[] fieldArr) {
        this.fieldMap.put(entityInfoEnum, fieldArr);
    }

    public void setFieldMap(Map<EntityInfoEnum, Field[]> fieldMap) {
        this.fieldMap = fieldMap;
    }

    public Map<EntityInfoEnum, String[]> getFieldStrMap() {
        return fieldStrMap;
    }

    public String[] getFieldStrArr(EntityInfoEnum entityInfoEnum) {
        return this.fieldStrMap.get(entityInfoEnum);
    }

    public void putFieldStrArr(EntityInfoEnum entityInfoEnum, String[] fieldStrArr) {
        this.fieldStrMap.put(entityInfoEnum, fieldStrArr);
    }

    public void setFieldStrMap(Map<EntityInfoEnum, String[]> fieldStrMap) {
        this.fieldStrMap = fieldStrMap;
    }

    public Class getRealClass() {
        return entity;
    }

    public String getSchema() {
        return schema;
    }

    public void setSchema(String schema) {
        this.schema = schema;
    }

    public String getSourceGroup() {
        return sourceGroup;
    }

    public void setSourceGroup(String sourceGroup) {
        this.sourceGroup = sourceGroup;
    }

    public Class getExcelEntity() {
        return excelEntity;
    }

    public void setExcelEntity(Class excelEntity) {
        this.excelEntity = excelEntity;
    }
}
